package com.user.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Configuration;

/**
 *
 * 配置类，Sping启动时候就可以初始化了
 *
 * @author:wesley
 */
public class UserConfig implements CommandLineRunner{


    /**
     *下面的配置都是从git远程仓库读取的
     */

    @Value("${spring.datasource.driverClassName}")
    private String driverClassName;

    @Value("${spring.datasource.url}")
    private String url;

    @Value("${spring.datasource.username}")
    private String username;

    @Value("${spring.datasource.password}")
    private String password;

    @Value("${from}")
    private String from;


    /**
     *
     * 实现CommandLineRunner方法， 在Spring加载完毕之后才执行这个方法。
     *
     * @param strings
     * @throws Exception
     */
    @Override
    public void run(String... strings) throws Exception {
        //在此添加微服务启动时候设置参数
        DataSourceProperties dsp = new DataSourceProperties();
        dsp.setUrl(url);
        dsp.setDriverClassName(driverClassName);
        dsp.setUsername(username);
        dsp.setPassword(password);


//        System.out.println("run init....");
//        System.out.println("driverClassName:"+driverClassName);
//        System.out.println("url:"+url);
//        System.out.println("username:"+username);
//        System.out.println("password:"+password);
//        System.out.println("from:"+from);
    }
}
